#include<cstdio>
#include<cstring>
const int MAXINT = 2100000000;
int t,n,m;
int a[21][1001],f[21][1001];
int max(int x,int y)
{
	return x>y?x:y;
}
void work()
{
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		for(int i = 1 ; i <= n; i++)
			for(int j=1; j <= m ; j++)
				scanf("%d",&a[i][j]);
		for(int i = 0 ; i <= n ; i++)
			for(int j = 0 ; j <= m; j++)
				f[i][j] = -MAXINT;
		f[1][1] = a[1][1];
		for(int i = 2 ; i <=n; i++ )
			f[i][1] = f[i-1][1] + a[i][1];
		for(int i = 1 ; i <= n; i++ )
		   for(int j = 2; j <= m; j++  )
		   {
			f[i][j] = max(f[i-1][j],f[i][j-1]);
			for(int k = 1; k < j-1; k++)
				if(j%k == 0)f[i][j]=max(f[i][j],f[i][k]);
			f[i][j] += a[i][j];	
		   }
		printf("%d\n",f[n][m]);
	}
}

int main()
{	
	work();
	return 0;
}
